@extends('layouts.back_stage')
@section('style')
@section('content')
    <link rel="stylesheet" href="{{env('CDN_DOMAIN_NAME')}}/css/clothInfo.css?v=1.0.2"/>
    <link href="{{env('CDN_DOMAIN_NAME')}}/css/jcDate.css" rel="stylesheet">
    <style>
        .seek_lab{width:190px;}
    </style>
    <div class="container">
        <div style="margin:30px;"><h3 >面辅料采购清单</h3></div>
        <ul class="lining-ul">
            <li id="ingred" class="lining-li">
                <form action="/purchase/purchaseList" type="post">
                <div style="overflow: hidden;">
                    <p class="seek_p" style="width:80%;">
                        <label class="seek_lab supplier_id2" name="supplier">供应商：
                            <select class="ingred_sel" name="supplier">
                                @if($where->supplier)
                                    <option value="{{ $where->supplier }}">{{ $supplier[$where->supplier] }}</option>
                                    @else
                                    <option value="">请选择</option>
                                    @endif
                                @foreach($supplier as $k=>$v)
                                    <option value="{{ $k }}">{{ $v }}</option>
                                @endforeach
                            </select>
                        </label>
                        <label class="seek_lab">季节：
                            <select class="ingred_sel use_season2"  name="season" >
                                @if($where->season)
                                    <option value="{{ $where->season }}">{{ $where->season }}</option>
                                @else
                                    <option value="">请选择</option>
                                @endif
                                <option value="春">春</option>
                                <option value="夏">夏</option>
                                <option value="秋">秋</option>
                                <option value="冬">冬</option>
                            </select>
                        </label>
                        <label class="seek_lab1" style="width:250px;">日期:
                            <input type="text" class="ingred_sel jcDate" name="end_at" value="{{ $where->end_at }}" placeholder="结束时间" style="width:100px;">
                            <span style="float:right;margin:2px;">-</span>
                            <input type="text" class="ingred_sel jcDate" name="start_at" value="{{ $where->start_at }}" placeholder="开始时间" style="width:100px;">
                        </label>
                    </p>
                    <p class="seek_p" style="width:80%;">
                        <label class="seek_lab">面料号：
                            <input type="text" class="ingred_sel fabric_num2" value="{{ $where->clothes }}" name="clothes">
                        </label>
                        <label class="seek_lab" style="width:220px;">审核状态：
                            <select class="ingred_sel check_status" style="width:150px;" name="status">
                                @if($where->status == 1)
                                    <option value="{{ $where->status }}">未审核</option>
                                @elseif($where->season == 2)
                                    <option value="{{ $where->status }}">已审核</option>
                                    @elseif($where->season == -1)
                                    <option value="{{ $where->status }}">未通过</option>
                                    @else
                                    <option value="">请选择</option>
                                @endif
                                    <option value="2">已通过</option>
                                    <option value="-1">未通过</option>
                                    <option value="1">未审核</option>
                            </select>
                        </label>
                        <label class="seek_lab1" style="width:240px;">制单人：
                            <input type="text" class="ingred_sel check_master" style="width:180px;" name="user_name" value="{{ $where->user_name }}" >
                        </label>
                            <button class="btn bt_del btn-info" href="javascript:;" >搜索</button>
                            <a class="btn bt_del btn-info" href="javascript:;" onclick="emptyIngred()">清空</a>
                    </p>
                </div>
                </form>
                <div class="fabric-choose" style="clear:both;">
                    <span>共<span class="in_count info_sum">{{ $total }}</span>条信息</span>
                    <button class="btn btn-primary bt_a print_list">打印</button>
                    <a class="btn btn-info bt_a" href="javascript:;" onclick="revampIngred()">修改</a>
                    <button class="btn bt_a btn-primary" onclick="addNew()">添加</button>
                    <a class="btn bt_a btn-danger renewStatus" href="javascript:;">反审</a>
                    <a class="btn bt_a btn-primary renewStatus" href="javascript:;">审核</a>
                </div>
                <div class="fabric_list">
                    <table class="fab" border="1" cellspacing="0" cellpadding="0">
                        <tr>
                            <td style="width:35px;"></td>
                            <td>采购计划单号</td><td>状态</td><td>供应商</td><td>销售季节</td><td>包含面辅料</td><td>数量</td><td>金额</td><td>采购下达日期</td><td>备注</td><td>到货状态</td><td>服务款号</td><td>采购类型</td><td>制单日期</td><td>制单人</td><td>合同号</td><td>合同签订人</td>
                        </tr>
                        @if(count($lists) > 0)
                            @foreach($lists as $v)
                                <tr class="ingred_{{ $v->id }}">
                                    {{--<td><input type="checkbox" class="allChoose" value="{{ $v->id }}"></td>--}}
                                    <td><input type="radio" name="radioAll" class="allChoose" value="{{ $v->id }}"></td>
                                    <td class='purchaseID'>{{ $v->plan_code }}</td>
                                        @if($v->status == 1 )
                                        <td class="inred" id="{{ $v->status }}">未审核</td>
                                        @elseif($v->status == 2)
                                        <td class="inred" style="color: #00a2d4" id="{{ $v->status }}">已审核(采购中)</td>
                                        @elseif($v->status ==3)
                                        <td class="inred" style="color: #00a2d4" id="{{ $v->status }}">已全部到库</td>
                                        @else
                                        <td class="inred" style="color: red" id="{{ $v->status }}">未通过</td>
                                        @endif
                                    <td>{{ $v->supplier_name }}</td>
                                    <td>{{ $v->season }}</td>
                                    <td>{{ $v->clothes }}</td>
                                    <td>{{ $v->num }}</td>
                                    <td>{{ $v->price }}</td>
                                    <td>{{ $v->purchase_date }}</td>
                                    <td>{{ $v->remarks }}</td>
                                    <td>
                                        @if($v->pro_status==0)  未到货
                                        @elseif($v->pro_status==1)  已到货
                                        @endif
                                    </td>
                                    <td>{{ $v->to_girard }}</td>
                                    <td>
                                        @if($v->purchase_status == 1)
                                            计划采购
                                        @endif
                                    </td>
                                    <td>{{ $v->created_at }}</td>
                                    <td>{{ $v->user_name }}</td>
                                    <td>{{ $v->contract_code }}</td>
                                    <td>{{ $v->contract_name }}</td>
                                </tr>
                            @endforeach
                         @endif
                    </table>
                </div>
            </li>
        </ul>
    </div>
    <div style="float: right;margin:20px 0;"><button class="btn btn-info" onclick="returnPage()" style="float:right;">跳转</button><input type="text" class="form-control returnPage" style="width:6rem;float: right;margin:0 5px;"></div>
    <div style="float: right">{{ $lists->appends(['supplier'=>$where->supplier,'season'=>$where->season,'end_at'=>$where->end_at,'user_name'=>$where->user_name,'start_at'=>$where->start_at,'status'=>$where->status,'clothes'=>$where->clothes])->links() }}</div>

    {{--遮罩层--}}
    <div class="mask" style="display:none;"></div>
    <script>
        $(function (){
            $(".jcDate").jcDate({
                IcoClass : "jcDateIco",
                Event : "click",
                Speed : 300,
                Left : 0,
                Top : 28,
                format : "-",
                Timeout : 100000
            });
        });
        //添加按钮
        function addNew(){
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'post',
                url:'/purchase/increaseList',
                dataType:'json',
                data:{
                    sign:1
                },
                success:function(event){
                    window.location.href='/purchase/editView?id='+event.info
                }
            })
        }
        /*清空按钮*/
        function emptyIngred(){
            $(".ingred_sel").each(function(){
                $(this).val("");
            })
        }
        /*审核反审*/
        $('.renewStatus').click(function(){
            var that_ = $(this);
            var n=0;
            for(var i=0; i< $(".allChoose").length;i++){
                if($(".allChoose")[i].checked){
                    var id=$(".allChoose")[i].value;
                    var getInred = $(".allChoose").eq(i).parent().siblings('.inred');
                    n++;
                }
            }
            if(n<=1 && n>0){
                var status;
                if($(this).text() == "审核"){
                    status = 2;
                    if(getInred.text() == "已审核(采购中)"){
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text('请不要重复审核！');
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        return false;
                    }
                }
                if($(this).text() == "反审"){
                    status = -1;
                    if(getInred.text() == "未通过"){
                        $(".faceImg").attr("src","/img/weep.png");
                        $(".oHandle").text('未通过的不能再反审');
                        $(".oSuccess").show(0).delay(1000).hide(0);
                        return false;
                    }
                }
                $(".oText").text('确定要'+$(this).text()+'吗？');
                $(".oMask").show();
                $(".oAnim").show();
                $(".oBtn0").attr('id','');
                $(".oBtn0").attr('id','oRefund');
                /*点确定*/
                $(document).on('click','#oRefund',function(){
                    $(".oMask").hide();
                    $(".oAnim").hide();
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        type: 'post',
                        url: '/finance/to-examine-purchase-list',
                        data: {
                            id: id,
                            status:status
                        },
                        dataType: 'json',
                        success: function (data) {

                            if (data.success == false) {
                                $(".faceImg").attr("src","/img/weep.png");
                                $(".oHandle").text(data.msg);
                                $(".oSuccess").show(0).delay(1000).hide(0);
                               
                            }else{

                                $(".faceImg").attr("src","/img/laugh.png");
                                $(".oHandle").text(that_.text()+'成功');
                                $(".oSuccess").show(0).delay(1000).hide(0);
                                setTimeout(function(){
                                    window.location.reload();
                                },1000);
                            }
                        }
                    });
                });
            }else{
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text('请选择一项进行'+$(this).text());
                $(".oSuccess").show(0).delay(1000).hide(0);
            }
        });
        /*修改*/
        function revampIngred(){
            var n=0;
            for(var i=0; i< $(".allChoose").length;i++){
                if($(".allChoose")[i].checked){
                    var id=$(".allChoose")[i].value;
                    var getInred = $(".allChoose").eq(i).parent().siblings('.inred');
                    n++;
                }
            }
            if(n<=1 && n>0){
                if(getInred.text() == "未通过" || getInred.text() == "已审核(采购中)"){
                    $(".faceImg").attr("src","/img/weep.png");
                    $(".oHandle").text(getInred.text()+'不能再修改！');
                    $(".oSuccess").show(0).delay(1500).hide(0);
                    return false;
                }
                window.location.href="/purchase/editView?id="+id;
            }else{
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text('请选择一项进行修改');
                $(".oSuccess").show(0).delay(1000).hide(0);
            }
        }
        /*打印*/
        $('.print_list').click(function () {
            var n=0;
            for(var i=0; i< $(".allChoose").length;i++){
                if($(".allChoose")[i].checked){
                    var id=$(".allChoose")[i].value;
                    n++;
                }
            }
            if(n<=1 && n>0){
                window.location.href="/purchase/printList?id="+id;
            }else{
                $(".faceImg").attr("src","/img/weep.png");
                $(".oHandle").text('请选择一项打印');
                $(".oSuccess").show(0).delay(1000).hide(0);
            }
        });
        /*全选*/
        $(".goAllChoose").click(function(){
            $(".allChoose").prop("checked",$(this).prop("checked"));
        });
    </script>
@endsection
@section('script')
    @parent
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/jQuery-jcDate.js" type="text/javascript"></script>
    <script src="https://www.jq22.com/jquery/jquery-migrate-1.2.1.min.js"></script><!--JQ的版本引导-->
@endsection
